package yznu_Servlet_vip;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import User_Utils.User;
import yznu_Bean_handle.Delete;
import yznu_Bean_handle.Query;
import yznu_Bean_handle.othersStoreOrder;
import yznu_Bean_handle.vipManager;

public class vipManegerSer extends HttpServlet {

	boolean f = false;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=gb2312");
		String status = request.getParameter("status");
		String Username = new String(request.getParameter("name").getBytes("iso-8859-1"),"utf-8");
		request.setAttribute("source", "修改");
		
		if(status.equals("update")){
			User user = new Query().Query_user(Username);
			request.setAttribute("user", user);
			RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/userUpdate.jsp");
			dispatcher.forward(request, response);
		}else if(status.equals("del")){
			f = new Delete().Del_user(Username);
			
			if(f){
				request.setAttribute("Msg", "删除成功");
				int currentPage=(Integer) request.getSession().getAttribute("currentPage");
				request.getSession().setAttribute("currentPage", currentPage);
				int countPage=new vipManager().countPage();
				request.getSession().setAttribute("countPage", countPage);
				ArrayList<User> users = new vipManager().selectAll(currentPage);

				request.setAttribute("users", users);
				RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/users.jsp");
				dispatcher.forward(request, response);
			}else{
				request.setAttribute("Msg", "删除失败");
				int currentPage=(Integer) request.getSession().getAttribute("currentPage");
				request.getSession().setAttribute("currentPage", currentPage);
				int countPage=new vipManager().countPage();
				request.getSession().setAttribute("countPage", countPage);
				ArrayList<User> users = new vipManager().selectAll(currentPage);

				request.setAttribute("users", users);
				RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/users.jsp");
				dispatcher.forward(request, response);
			}
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doGet(request, response);
	}

}
